package com.itheima.controller.mobile;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.service.ValidateCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/validatecode")
public class ValidateCodeController {
    @Autowired
    private ValidateCodeService validateCodeService;

    /**
     * 发送手机验证码
     * @param telephone
     * @return
     */
    @GetMapping("/send4Login")
    public Result send4Login(String telephone) {
        Boolean success = validateCodeService.sendValidateCode4Phone(telephone);
        if(success){
            return new Result(true, MessageConstant.SEND_VALIDATECODE_SUCCESS);
        }else {
            return new Result(false, MessageConstant.SEND_VALIDATECODE_FAIL);
        }
    }
    /**
     * 发送手机验证码
     * @param telephone
     * @return
     */
    @PostMapping("/send4Order")
    public Result send4Order(String telephone) {
        Boolean success = validateCodeService.sendValidateCode4Phone(telephone);
        if(success){
            return new Result(true, MessageConstant.SEND_VALIDATECODE_SUCCESS);
        }else {
            return new Result(false, MessageConstant.SEND_VALIDATECODE_FAIL);
        }
    }
}

